;(function () {
    var options = {};
    var pieces = Array();
    $(function () {
        initEvent();
    });

    function initEvent() {
        showMap();
        showPie();
        getPieOne();
        getPieTwo();
        getCountByRegion();
        getBar();
        getPie();
    }

    function getCountByRegion() {
        $.get("https://www.easy-mock.com/mock/5d281cc85296dd579b13b342/webstie/getCountByRegion", {}, function (data) {
            var data = data.obj;
            var datalist = new Array();
            $.each(data, function (index, item) {
                var i = {};
                i["value1"] = '注册人员：' + item.zc + '人</br>岗位人员：' + item.gw + '人</br>安管人员：' + item.ag + '人</br>特种人员：' + item.tz + '人</br>技术工人：' + item.js + '人</br>职称人员：' + item.zcr + '人';
                i["name"] = item.regionName;
                i["value"] = Number(item.zc) + Number(item.gw) + Number(item.ag) + Number(item.tz) + Number(item.js) + Number(item.zcr);
                datalist.push(i);
            });

            pieces = [
                {gte: 50000, color: '#3284ff'},
                {gte: 25000, lt: 50000, color: '#669dec'},
                {gte: 10000, lt: 25000, color: '#96bcf2'},
                {gte: 500, lt: 10000, color: '#cbdef8'},
                {lt: 5000, color: '#eef0fd'}
            ];
            showMap(datalist);
        });
    }

    function showMap(data) {
        var myChart2 = echarts.init(document.getElementById("map2"));
        $.get('/webstie/assets/js/data-jiangxi.json ', function (geoJson) {
            echarts.registerMap('jiangxi', geoJson);
            option = {
                tooltip: {
                    trigger: 'item',
                    formatter: function (params) {
                        var s = "";
                        var myseries = option.series;
                        for (i in myseries) {
                            for (var j = 0; j < myseries[i].data.length; j++) {
                                if (myseries[i].data[j].name == params.name) {
                                    s += myseries[i].data[j].name + '</br>' + myseries[i].data[j].value1 + '</br>';
                                }
                            }
                        }
                        return s;
                    }
                },
                visualMap: {
                    type: 'piecewise',
                    pieces: pieces,
                    right: '1%'
                },
                series: [
                    {
                        name: '',
                        type: 'map',
                        mapType: 'jiangxi', // 自定义扩展图表类型
                        itemStyle: {
                            normal: {label: {show: true}},
                            emphasis: {label: {show: true}, color: '#fce15c'},
                        },
                        data: data

                    }
                ]
            };
            myChart2.setOption(option)
        });

    }

    function showPie() {
        var colorList = ['#3AA1FF', '#36CBCB', '#4ECB73', '#FBD437', '#F2637B'];
        option = {
            tooltip: {
                trigger: 'item',
                formatter: "{b} : {c}"
            },
            legend: {
                // orient: 'vertical',
                x: 'center',
                y: 'bottom',
                data: ['事例一', '事例二', '事例三', '事例四', '事例五'],
                icon: 'circle',
                itemGap: 20,
                textStyle: {
                    padding: [2, 0, 0, 0]
                }
            },
            grid: {
                top: 30,
                bottom: 30,
                left: 100,
                right: 100
            },
            series: [
                // 主要展示层的
                {
                    radius: '60%',
                    center: ['50%', '50%'],
                    type: 'pie',
                    itemStyle: {
                        normal: {
                            color: function (params) {
                                return colorList[params.dataIndex]
                            }
                        }
                    },
                    labelLine: {
                        normal: {
                            show: true,
                            length: 25,
                            length2: 0,
                            lineStyle: {
                                // color: '#f00'
                            },
                            align: 'right'
                        },
                        color: "#1890ff",
                        emphasis: {
                            show: true
                        }
                    },
                    label: {
                        normal: {
                            formatter: '{b} {d}%'
                        }
                    },
                    data: [{
                        value: 80,
                        name: '实例一',
                    }, {
                        value: 42,
                        name: '实例二'
                    }, {
                        value: 34,
                        name: '实例三'
                    }, {
                        value: 26,
                        name: '实例四'
                    }, {
                        value: 18,
                        name: '实例六'
                    }
                    ],
                },

            ]
        };
    }

    function getPieOne() {
        showPie();
        var myChart1 = echarts.init(document.getElementById("pie1"));
        myChart1.setOption(option)
    }

    function getPieTwo() {
        showPie();
        var myChart3 = echarts.init(document.getElementById("pie3"));
        myChart3.setOption(option)
    }

    function getBar() {
        option = {
            color: ['#3AA1FF'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                },
                formatter: "{b}  : {c}人"
            },
            grid: {
                left: '5%',
                right: '5%',
                bottom: '2%',
                containLabel: true
            },
            xAxis: {
                type: 'value',
                // boundaryGap: [0, 0.0001],
                axisLabel: {
                    formatter: '{value}',
                    textStyle: {
                        color: '#9E9E9E',
                        fontWeight: '80'
                    }
                },
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                splitLine: {
                    show: true,
                    // interval: 'auto',
                    lineStyle: {
                        color: ['#eee'],
                        width: 1,
                        type: 'dashed'
                    }
                }
            },
            yAxis: {
                type: 'category',
                data: ['检测服务类', '造价咨询类', '规划设计类', '测量调查类', '咨询评估类', '其他服务类'],
                axisLabel: {
                    show: true,
                    rotate: 0,
                    margin: 10,
                    inside: false,
                    textStyle: {
                        color: '#9E9E9E',
                        fontWeight: '50'
                    }
                },
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
            },
            series: [{
                type: 'bar',
                barMaxWidth:25,
                label: {
                    normal: {
                        show: true,
                        position: 'right',
                        formatter: function (v) {
                            var val = v.data;
                            if (val == 0) {
                                return '';
                            }
                            return val;
                        },
                        color: '#9E9E9E'
                    }
                },
                data: [122, 133, 441, 515, 661, 771]
            }]
        };
        var myChart4 = echarts.init(document.getElementById("bar4"));
        myChart4.setOption(option)
    }

    function getPie() {
        var colorList = ['#3AA1FF', '#36CBCB', '#4ECB73', '#FBD437', '#F2637B', '#8543E0'];
        option = {
            tooltip: {
                trigger: 'item',
                formatter: "{b} : {c}<br/>占比 : {d}%"
            },
            legend: {
                // orient: 'vertical',
                x: 'center',
                y: 'bottom',
                data: ['事例一', '事例二', '事例三', '事例四', '事例五'],
                icon: 'circle',
                itemGap: 20,
                textStyle: {
                    padding: [2, 0, 0, 0]
                }
            },
            grid: {
                top: 30,
                bottom: 30,
                left: 100,
                right: 100
            },
            series: [
                // 主要展示层的
                {
                    radius: '80%',
                    center: ['50%', '50%'],
                    type: 'pie',
                    roseType: "radius",
                    itemStyle: {
                        normal: {
                            color: function (params) {
                                return colorList[params.dataIndex]
                            }
                        }
                    },
                    label: {
                        normal: {
                            show:false,
                        }
                    },
                    data: [{
                        value: 80,
                        name: '实例一',
                    }, {
                        value: 69,
                        name: '实例二'
                    }, {
                        value: 44,
                        name: '实例三'
                    }, {
                        value: 36,
                        name: '实例四'
                    }, {
                        value: 28,
                        name: '实例五'
                    }, {
                        value: 18,
                        name: '实例五'
                    }
                    ],
                },

            ]
        };
        var myChart5 = echarts.init(document.getElementById("pie5"));
        myChart5.setOption(option)
    }



})(jQuery);